<%@Page Language="VB"%>

<%@Import Namespace="System.Data" %>

<%@ Register TagPrefix="wrox" TagName="connect" Src="..\global\connect-strings.ascx" %>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html><head>
<title>Reading Data into a DataSet from an XML File</title>
<!-- #include file="..\global\style.inc" -->
</head>
<body bgcolor="#ffffff">
<span class="heading">Reading Data into a DataSet from an XML File</span><hr />
<!--------------------------------------------------------------------------->

<div id="outMessage" runat="server"></div><br />
<b>DataSet.Tables Collection</b>
<asp:datagrid id="dgrTables" runat="server" /><br />
<b>Contents of DataSet.Tables("Books")</b>
<asp:datagrid id="dgrValues" runat="server" />

<script language="VB" runat="server">

Sub Page_Load()

   'create a new DataSet object
   Dim objDataSet As New DataSet()

   Try

      'use the path to the current virtual application
      Dim strVirtualPath As String = Request.ApplicationPath & "XML-from-DataSet.xml"
      Dim strVSchemaPath As String = Request.ApplicationPath & "Schema-from-DataSet.xsd"

      'read the schema and data into the DataSet from an XML document on disk
      'must use the Physical path to the file not the Virtual path
      objDataSet.ReadXMLSchema(Request.MapPath(strVSchemaPath))
      outMessage.InnerHTML = "Reading file: <b><a href=" & Chr(34) & strVSchemaPath & Chr(34) _
                & ">" & strVSchemaPath & "</a></b><br />"

      objDataSet.ReadXML(Request.MapPath(strVirtualPath))
      outMessage.InnerHTML += "Reading file: <b><a href=" & Chr(34) & strVirtualPath & Chr(34) _
                           & ">" & strVirtualPath & "</a></b>"

   Catch objError As Exception

      'display error details
      outMessage.InnerHTML = "<b>* Error while reading disk file</b>.<br />" _
          & objError.Message & "<br />" & objError.Source & "<br />" _
          & "Run the previous example to create the disk file"
      Exit Sub  ' and stop execution

   End Try

   'now we can display the DataSet contents

   'assign the DataView.Tables collection to first the DataGrid control
   dgrTables.DataSource = objDataSet.Tables
   dgrTables.DataBind()  'and bind (display) the data

   'create a DataView object for the Books table in the DataSet
   Dim objDataView As New DataView(objDataSet.Tables("Books"))

   'assign the DataView object to the second DataGrid control
   dgrValues.DataSource = objDataView
   dgrValues.DataBind()  'and bind (display) the data

End Sub
</script>


<!--------------------------------------------------------------------------->
<!-- #include file="..\global\foot.inc" -->
</body>
</html>
